// 树扁平化
/**
 * tree: {
 *  value: value,
 *  label: label,
 *  children: []
 * }
 */

function TreeToArray(tree) {
  let arr = [];
  const arrTree = [tree]
  function getArray(tree) {
    for (let i = 0; i < tree.length; i++) {
      let tempTree = { ...tree[i] }
      if (tempTree) {
        arr.push({ label: tempTree.label, value: tempTree.value })
      }
      if (tempTree?.children?.length) {
        getArray(tempTree?.children)
      }
    }
  }
  getArray(arrTree)
  return arr;
}

const tree = {
  label: '123',
  value: '234',
  children: [
    {
      label: 'child1',
      value: 'child1',
      children: [
        {
          label: 'child11',
          value: 'child11',
        },
        {
          label: 'child12',
          value: 'child12',
        },
      ]
    },
    {
      label: 'child2',
      value: 'child2',
      children: [
        {
          label: 'child21',
          value: 'child21',
        },
      ]
    }
  ]
}

const arr = TreeToArray(tree);
console.log(arr);